package CustomUI;

import org.Consts;
import org.json.JSONException;
import org.json.JSONObject;

import com.ydev.graphics.animations.R;

import DTO.Properties;
import android.R.bool;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.CheckBox;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class ShapePropertiesDialog extends Dialog {

	SeekBar skWidth=new SeekBar(getContext());
	TextView tvWidth=new TextView(getContext());
	 CheckBox chFill;
	 
	 Properties props=new Properties(Consts.DRAWING_ACTIONS_Shape);
	 
	public ShapePropertiesDialog(Context context) {
		super(context);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.setContentView(R.layout.shape_properties_dialog);
		this.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
		LayoutParams params = getWindow().getAttributes();
        params.width = LayoutParams.FILL_PARENT;
        getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
        
        tvWidth=(TextView)findViewById(R.id.tVWidth);
        
        chFill=(CheckBox)findViewById(R.id.checkBoxFill);
        
        skWidth=(SeekBar)findViewById(R.id.skWidth);
        
        final ydButton ydButtonShape = (ydButton) findViewById(R.id.ydButtonShape);
    	ydButtonShape.setSelected(true);
    	
    	
    	final ydButton ydButtonOtherShape1 = (ydButton) findViewById(R.id.ydButtonOtherShape1);
		//changeShapeClicked(ydButtonShape, ydButtonOtherShapes);
	
		final ydButton ydButtonOtherShape2 = (ydButton) findViewById(R.id.ydButtonOtherShape2);
		//changeShapeClicked(ydButtonShape, ydButtonOtherShapes);
	
		final ydButton ydButtonOtherShape3 = (ydButton) findViewById(R.id.ydButtonOtherShape3);

		ydButtonShape.addOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ydButtonShape.setSelected(true);
				ydButtonOtherShape1.setSelected(false);
				ydButtonOtherShape2.setSelected(false);
				ydButtonOtherShape3.setSelected(false);
				props.shape=Consts.DRAWING_SHAPE_RECTANGLE;
			}
		});
		
		ydButtonOtherShape1.addOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ydButtonShape.setSelected(false);
				ydButtonOtherShape1.setSelected(true);
				ydButtonOtherShape2.setSelected(false);
				ydButtonOtherShape3.setSelected(false);
				props.shape=Consts.DRAWING_SHAPE_CIRCLE;
			}
		});

ydButtonOtherShape2.addOnClickListener(new View.OnClickListener() {
	
	@Override
	public void onClick(View v) {
		ydButtonShape.setSelected(false);
		ydButtonOtherShape1.setSelected(false);
		ydButtonOtherShape2.setSelected(true);
		ydButtonOtherShape3.setSelected(false);
		props.shape=Consts.DRAWING_SHAPE_LINE;
	}
});

ydButtonOtherShape3.addOnClickListener(new View.OnClickListener() {
	
	@Override
	public void onClick(View v) {
		ydButtonShape.setSelected(false);
		ydButtonOtherShape1.setSelected(false);
		ydButtonOtherShape2.setSelected(false);
		ydButtonOtherShape3.setSelected(true);
		props.shape=Consts.DRAWING_SHAPE_ARC;
	}
});
        
        
        skWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				tvWidth.setText((skWidth.getProgress()+1)+"");
				
			}
		});
	}

	public int getBrushWidth() {
		
		return skWidth.getProgress()+1;
	}
	
	public boolean getFillProperty(){
		return chFill.isChecked();
	}
	
	public void changeShapeClicked(final ydButton current, final ydButton chosen) {
		chosen.addOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				
				chosen.setSelected(true);
			}
		});
	}
	

}
